package tb4coding.sprider4lagou.util;

import java.io.IOException;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class GetSessionFactory {
	
	private SqlSessionFactory sessionFactory;
	private static GetSessionFactory myBatisUtil;
	
	
	public static GetSessionFactory getInstace(){
		if(myBatisUtil==null){
			myBatisUtil = new GetSessionFactory();
		}
		return myBatisUtil;
	}
	
	
	public GetSessionFactory(){
		if(sessionFactory==null){
			try {
				sessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-config.xml"));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}


	public SqlSessionFactory getSessionFactory() {
		return sessionFactory;
	}


	public void setSessionFactory(SqlSessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	

}
